package com.atguigu.oss.controller;

import com.atguigu.commonutils.R;
import com.atguigu.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by Miracle yaochengwei on 2020/8/8 10:51
 */
@RestController  //交给spring管理，返回json数据
@RequestMapping("/eduoss/fileoss")  //请求地址
@CrossOrigin //解决跨域问题
public class OssController {
    @Autowired
    private OssService ossService;
    //上传头像方法  //都返回的是R对象
    @PostMapping
    public R uploadOssFile(MultipartFile file){
        //获取上传文件  MultipartFile
        //返回上传oss路径
        String url = ossService.uploadFileAvator(file);
        return R.ok().data("url",url);  //返回url 他的值是url
    }
}
